package com.bm.exception;

import com.bm.Result.CodeEnum;
import com.bm.Result.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author hch
 * @version 1.0
 * @description 自定义异常
 * @date 2024/3/1 19:43
 */
//增强器
@ControllerAdvice
public class BmExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(Exception e){
        return Result.FAIL(e.getMessage());
    }

    @ExceptionHandler(BmException.class)
    @ResponseBody
    public Result error(BmException e){
        return Result.builder().
                code(CodeEnum.SYSTEM_ERROR.getCode()).
                msg(e.getMessage()).build();
    }
}
